package com.ruoyi.web.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.NewsUpdate;
import com.ruoyi.web.service.NewsUpdateCrawlerService;
import com.ruoyi.web.service.NewsUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * <p>
 * 资讯动态表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-11-01
 */
@RestController
@RequestMapping("/news-update")
public class NewsUpdateController extends BaseController {
    @Autowired
    private NewsUpdateCrawlerService newsUpdateCrawlerService;

    @Autowired
    private NewsUpdateService newsUpdateService;

    @GetMapping("test")
    public AjaxResult test(){
        newsUpdateCrawlerService.crawlAllArticles();
        return AjaxResult.success();
    }


    @PostMapping
    public AjaxResult insert(@RequestBody NewsUpdate newsUpdate){
        newsUpdateService.insertRecord(newsUpdate);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult update(@RequestBody NewsUpdate newsUpdate){
        newsUpdateService.updateRecord(newsUpdate);
        return AjaxResult.success();
    }

    @DeleteMapping
    public AjaxResult delete(@RequestParam("baseId") Long baseId){
        newsUpdateService.deleteRecord(baseId);
        return AjaxResult.success();
    }

    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam("baseId") Long baseId){
        return AjaxResult.success(newsUpdateService.detail(baseId));
    }


    @GetMapping("/page")
    public TableDataInfo page(){
        startPage();
        return getDataTable(newsUpdateService.selectList());
    }



}
